<?php

/**
 * Created by Reliese Model.
 */

namespace App\Models;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * Class JournalContent
 *
 * @property int $id
 * @property string|null $cn_enterprise_full
 * @property string|null $cn_enterprise_short
 * @property string|null $en_enterprise_full
 * @property string|null $en_enterprise_short
 * @property string|null $en_address
 * @property string|null $cn_address
 * @property string|null $post_code
 * @property string|null $telephone
 * @property string|null $wx
 * @property string|null $e_mail
 * @property string|null $url
 * @property string|null $other
 * @property string|null $files
 * @property string|null $cn_company_introduction
 * @property string|null $en_company_introduction
 * @property string|null $main_business
 * @property int|null $status
 * @property Carbon|null $created_at
 * @property Carbon|null $updated_at
 * @property string|null $deleted_at
 * @property int|null $exhibitor_information_id
 *
 * @package App\Models
 */
class JournalContent extends Model
{
    use SoftDeletes;

    protected $table = 'journal_content';

    protected $casts = [
        'status' => 'int',
        'exhibitor_information_id' => 'int'
    ];

    protected $fillable = [
        'cn_enterprise_full',
        'cn_enterprise_short',
        'en_enterprise_full',
        'en_enterprise_short',
        'en_address',
        'cn_address',
        'post_code',
        'telephone',
        'wx',
        'e_mail',
        'url',
        'other',
        'files',
        'cn_company_introduction',
        'en_company_introduction',
        'main_business',
        'status',
        'exhibitor_information_id',
        'main_products',
    ];

    public function exhibitor_information()
    {
        return $this->belongsTo(ExhibitorInformation::class, 'exhibitor_information_id', 'id');
    }

    public function getMainBusinessAttribute($value)
    {
        $main_business = json_decode($value, true);

        return implode(',', $main_business);
    }

    public function setMainBusinessAttribute($value)
    {
        $this->attributes['main_business'] = json_encode($value);
    }

}
